package io.renren.controller;

import io.renren.annotation.Login;
import io.renren.common.utils.ConvertUtils;
import io.renren.common.utils.Result;
import io.renren.dto.repair.RepairEvaluationDTO;
import io.renren.entity.repair.RepairEvaluationEntity;
import io.renren.service.repair.RepairEvaluationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("api/evaluation")
@Tag(name = "评价表")
public class ApiEvaluationController {
    
    @Resource
    private RepairEvaluationService repairEvaluationService;
    
    /**
     * 添加评价
     */
    @Login
    @PostMapping("/add")
    @Operation(summary = "添加评价")
    public Result add(@RequestBody RepairEvaluationDTO dto, @RequestAttribute("userId") Long userId) {
        dto.setUserId(userId); // 设置当前用户ID
        repairEvaluationService.save(dto);
        return new Result();
    }
    
    /**
     * 获取评价信息
     */
    @Login
    @GetMapping("/info")
    @Operation(summary = "获取评价信息")
    public Result<RepairEvaluationEntity> info(@RequestParam Long repairId) {
        RepairEvaluationEntity evaluation = repairEvaluationService.getByRepairId(repairId);
        return new Result<RepairEvaluationEntity>().ok(evaluation);
    }
    
    /**
     * 判断是否已评价
     */
    @Login
    @GetMapping("/isEvaluated")
    @Operation(summary = "判断是否已评价")
    public Result<Boolean> isEvaluated(@RequestParam Long repairId) {
        boolean evaluated = repairEvaluationService.isEvaluated(repairId);
        return new Result<Boolean>().ok(evaluated);
    }
}
